<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>组织结构</title>
<%@include file="/common/jsp/taglib.jsp"%>
<script type='text/javascript' src="${ctx }dwr/engine.js"></script>
<script type='text/javascript' src="${ctx }dwr/util.js"></script>
<script type='text/javascript' src="${ctx }dwr/interface/basicDwrService.js"></script>

<link rel="stylesheet" href="${ctx }common/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${ctx }common/zTree_v3/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }common/zTree_v3/js/jquery.ztree.core-3.5.js"></script>	

<script type="text/javascript">
//页面初始化
$(document).ready(function(){
		
		var setting = {
				data: {
					simpleData: {
						enable: true
					}
				},
				async:{
					 contentType:"application/json",  
					 enable:true,  
					 type:"post",  
					url: ctx + "basic/organizationTree.do"
				},
				callback:{
					onClick:function(event, treeId, treeNode){
//						console.info(treeNode.tId + ", " + treeNode.name);
//						console.info(treeNode.id);
						var url = ctx +"common/s.do";
						var data1 = {
								tOrganizationId : treeNode.id,
								tourl: "${tourl }",
								statement: "${statement }"
						};
						common.loadPage(url, data1);
					}
				}
		
			};

		$.fn.zTree.init($("#treeDemo"), setting);
		

		var url4 = ctx+"basic/o_name.do?o_id=${mp.tOrganizationId }";
		if("" == '${mp.tOrganizationId }'){
			url4 = ctx+"basic/o_name.do?o_id=1";
		}

		common.jajax(url4,function(d){
			$("#now_o").html("当前机构:"+d.name);
		});
		
		
});//end of document.ready***********


//组织机构弹出层修改增加
function addOrganization(){
	$("#o_name").val("");
	$("#o_code").val("");
	$("#flag").val("add");
	$("#organizationTitle").html("新建机构");
}
function editOrganization(){
	common.jajax(ctx+"basic/o_name.do?o_id=${mp.tOrganizationId }",function(d){
		
		$("#o_name").val(d.name);
		$("#o_code").val(d.code);
		$("#flag").val("edit");
		$("#organizationTitle").html("编辑机构");
		
	});
	
	
	
}
function deleteOrganization(){
	common.confirmMes('将删除机构下的员工,确定要删除该机构吗?',function(){
		 basicDwrService.deleteOrganization('${mp.tOrganizationId }', function(d){
				if(d.isok == '1'){
					var url = ctx +"common/s.do";
					var data1 = {
							tOrganizationId : d.p_id,
							tourl: "ass/basicmanage/organization_n",
							statement: "userManage_SpecSql.getUserRelated"
					};
					$("#myModal_editO_close").click();
					common.loadPage(url, data1);
				}else{
					common.alertMes(d.msg,null);
				}
			});
	 });
}


function submitForm(){
	if(!stringCheck($("#o_name").val())){
			common.alertMes("机构名称不合法",null);
			return false;
		}
	if(!stringCheck($("#o_code").val())){
		common.alertMes("机构编码不合法",null);
		return false;
	}
	var data = $("#editOform").serialize();
	var url = ctx + "basic/saveOrEditOrganization.do";
	common.dajax(url,data,function(d){
		if(d.code == "ok"){
			var url = ctx +"common/s.do";
			var data1 = {
					tOrganizationId : '${mp.tOrganizationId }',
					tourl: "ass/basicmanage/organization_n",
					statement: "userManage_SpecSql.getUserRelated"
			};
			$("#myModal_editO_close").click();
			common.loadPage(url, data1);
		}else{
			common.alertMes(d.code,null);
		}
	});
	return ;
}

//页面跳转修改增加
function addUser(){
	var url = ctx + "basic/addEditUser.do";
	var param = {
			statement: '${statement}',
			tourl: '${tourl}',
			organizationid : '${mp.tOrganizationId }' ,
			flag : "add"
	}
	common.loadPage(url,param);
	
}
function editUser(uid){
	var url = ctx + "basic/addEditUser.do";
	var param = {
			statement: '${statement}',
			tourl: '${tourl}',
			organizationid : '${mp.tOrganizationId }' ,
			flag : "edit",
			uid : uid
	}
	common.loadPage(url,param);
}
function deleteUser(uid){
	common.confirmMes("确定要删除用户吗?",function(){
		basicDwrService.deleteUser(uid,function(){
			var param = {
				statement: '${statement}',
				tourl: '${tourl}'
		}
		common.loadPage(ctx+"common/s.do",param);
		});
	});
	
	
}

function submitUForm(){
	
	
}







</script>
	
	<style type="text/css">
		.ztreeleft {
			margin: 15px 0px 20px 30px;
			/*width: 15%;*/
			text-align: left;
			float: left;
			border-right: 1px solid #cdcfcf;
			border-top: 1px solid #cdcfcf;
		}
		.contentright{
			margin: 15px 0px 20px 0px;
			width:74%;
			/*height: 800px;*/
			float: left;
			border-left: 1px solid #cdcfcf;
			border-top: 1px solid #cdcfcf;
		}
		.addPng{
			background-image: url("${ctx }common/ztree3/css/zTreeStyle/img/diy/add.png");
		}
		.deletePng{
			background-image: url("${ctx }common/ztree3/css/zTreeStyle/img/diy/delete.png");
		}
		#organizationDiv_ dl{
			margin: 5px 25px;
		
		}
		#userInfoDiv_ dl{
			margin: 5px 25px;
			width:700;
		}
		.uinfo{
			height: 300px;
			width: 240px;
			float: left;
		}
		.urole{
			border-left: 1px solid #cdcfcf;
			border-right: 1px solid #cdcfcf;
			height: 300px;
			float: left;
			width: 240px;
		}
		
		.upermission{
			height: 300px;
			width: 200px;
			float: left;
			overflow: auto;
		}
	</style>
</head>

<body>
	<div >
		<div class="ztreeleft">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
	
		<div class="contentright" id="contentright" >
		<!-- 表格 begin----------------- -->
				<div class="row">
					<div class="col-lg-12">
						<section class="panel">
							<header class="panel-heading">
								<span class="tools pull-left"> 
								<a class="icon-search" style="padding:10px;" href="javascript:void(0);" onclick="goUp(this);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
								</span>
								<div class="clearfix">
									<div class="pull-right">
									<span class="label  label-warning " id="now_o">
										</span>
										&nbsp;
										<button class="label btn label-info " href="#myModal_editorganization" data-toggle="modal"
											onclick="addOrganization();">&nbsp;新建子机构&nbsp;<i
											class="icon-plus"></i>&nbsp;
										</button>&nbsp;
										<span class="label btn label-info " href="#myModal_editorganization" data-toggle="modal"
											onclick="editOrganization();">&nbsp;编辑机构&nbsp;<i
											class="icon-edit"></i>&nbsp;
										</span>&nbsp;
										<span class="label btn label-info "  
											onclick="deleteOrganization();">&nbsp;删除机构&nbsp;<i
											class="icon-minus"></i>&nbsp;
										</span>
										
										&nbsp;&nbsp;&nbsp;&nbsp;
									
									
										<span class="label btn label-success green" href="myModal_edituser" data-toggle="modal"
											onclick="addUser();">&nbsp;用户&nbsp;<i
											class="icon-plus"></i>&nbsp;
										</span>
									</div>
								</div>
							</header>
							<div class="panel-body" style="display: none;">
								<form id="searchUserForm" role="form" class="form-inline" >
								<input type="hidden" name="statement" value="${statement }"  />
								<input type="hidden" name="tourl" value="${tourl }"  />
								<input type="hidden" name="tOrganizationId" id="tOrganizationId" value="${mp.tOrganizationId }"  />
								
			                        <div class="form-group">
			                            <label for="menuName" >用户名</label>
			                            <input type="text" placeholder="username" name="username" id="username" value="${mp.username }" class="form-control" >
			                        </div>
			                        <div class="form-group">
			                            <label for="menuName" >登录名</label>
			                            <input type="text" placeholder="loginname" name="loginname" id="loginname" value="${mp.loginname }" class="form-control" >
			                        </div>
			                        <button style="margin-top: 23px;"  class="btn btn-success" type="button" onclick="common.submitForm('searchUserForm')"  >查询</button>
			                        <button style="margin-top: 23px;"  class="btn btn-default" type="button" onclick="common.clearForm('searchUserForm')">重置</button>
			                    </form>
								
							</div>
			
			
							<table class="table table-striped table-advance table-hover">
								<thead>
									<tr>
										<th><i class="icon-bookmark"></i>序号</th>
										<th><i class="icon-bookmark"></i>用户名</th>
										<th><i class="icon-bookmark"></i>登录名</th>
										<th><i class="icon-bookmark"></i>机构名称</th>
										<th><i class="icon-bookmark"></i>拥有角色</th>
										<th><i class="icon-edit"></i> 操作</th>
			
									</tr>
								</thead>
								<tbody>
									<c:forEach var="p" items="${pageGrid.rows }" varStatus="ind">
										<tr>
											<td>${ind.index +1}</td>
											<td>${p.name }</td>
											<td>${p.loginName }</td>
											<td>${p.organizationName }</td>
											<td>${p.dbrolenames }</td>
											<td>
												<button class="btn btn-primary btn-xs" href="myModal_edituser" data-toggle="modal"
													onclick="editUser(${p.id});">
													<i class="icon-edit" title="编辑">编辑</i>
												</button>
												<button class="btn btn-danger btn-xs" 
													onclick="deleteUser(${p.id });">
													<i class="icon-trash" title="删除">删除</i>
												</button>
											</td>
											
										</tr>
									</c:forEach>
			
								</tbody>
							</table>
						</section>
					</div>
				</div>
			
				<!-- 主体内容结束 -->
				<!-- 分页 -->
				<input type="hidden" value="searchUserForm" id="currentFormId" />
				<jsp:include page="/common/system/pager.jsp" flush="true" />
				
				
			<!-- 表格 end----------------- -->
		</div>
	
	</div>
	



<!-- ------------------------- -->



<div aria-hidden="false" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal_editorganization" class="modal fade in" >
  <div class="modal-dialog">
	  <div class="modal-content">
		  <div class="modal-header">
			  <button aria-hidden="true" id="myModal_editO_close"  data-dismiss="modal" class="close" type="button" >×</button>
			  <h4 class="modal-title" id="organizationTitle"></h4>
		  </div>
		  <div class="modal-body">
			  <form role="form" class="form-horizontal" id="editOform" >
			  <input type="hidden" name="o_id" id="o_id" value="${mp.tOrganizationId }"  />	
              <input type="hidden" name="flag" id="flag" />
              <input type="hidden" name="statement1" value="${statement }"  />
			  <input type="hidden" name="tourl1" value="${tourl }"  />
              <div class="form-group">
                   <label class="col-lg-2 col-sm-2 control-label" for="o_name">机构名称</label>
                   <div class="col-lg-10">
                       <input type="text" placeholder="" id="o_name" name="o_name" class="form-control">
                   </div>
               </div>
               <div class="form-group">
                   <label class="col-lg-2 col-sm-2 control-label" for="o_code">机构编号</label>
                   <div class="col-lg-10">
                       <input type="text" placeholder="" id="o_code" name="o_code" class="form-control">
                   </div>
               </div>
				  <div class="form-group">
				  <div class="col-lg-5" ></div>
				  		<div class="col-lg-5" >
						  <button class="btn btn-primary" type="button" onclick="submitForm();">确认</button>
						  </div>
				  </div>
			  </form>
		  </div>
	  </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>	













		
</body>

</html>